<?php

namespace App\Http\ViewComposers;

use Illuminate\View\View;
use App\Services\GameTool\ChatLogService;

class ChatComposer
{
    protected $channelService;

    public function __construct(ChatLogService $chatLogService)
    {
        $this->chatLogService = $chatLogService;
    }

    public function compose(View $view)
    {
        $chatChannels = $this->chatLogService->getChatChannelTypes();
        $reqChatChannelId = $view->reqChatChannelId;

        //拼出 聊天频道
        $str_arr_chat_channel_id = '';
        $chatHtml = '';

        foreach ($chatChannels as $value) {
            $id = $value['chat_channel_id'];
            $name = $value['chat_channel_name'];
            $checked = '';
            
            if (empty($reqChatChannelId) || in_array($id, $reqChatChannelId)) {
                $checked = 'checked="checked"';
                $str_arr_chat_channel_id .= $id . ',';
            }


            $chatHtml .= <<<EOF
<div class="col-sm-2" style="min-width: 20rem">
     <label>&emsp;$name<input class="pull-left" type="checkbox" name="chat_channel_id[]" $checked value="$id"></label>
</div>
EOF;
        }
        $str_arr_chat_channel_id = (empty($str_arr_chat_channel_id) ? '' : substr($str_arr_chat_channel_id, 0, -1));

        $view->with(compact('str_arr_chat_channel_id', 'chatHtml'));
    }
}